import numpy as np

from models import *

class SIMULATION:
	
	unit_type = np.dtype(  [ \
	                   ('L_units', np.str_, 32), \
			           ('T_units', np.str_, 32), \
			           ('M_units', np.str_, 32), \
			           ('V_units', np.str_, 32), \
			           ('L_mks'  , np.float64 ), \
			           ('T_mks'  , np.float64 ), \
			           ('M_mks'  , np.float64 ), \
			           ('V_mks'  , np.float64 )]  )
	
	sim_type  = np.dtype(  [ \
					   ('N massless', np.int32),    \
					   ('N massive' , np.int32),    \
					   ('Sim time'  , np.float64 ), \
					   ('Max dt '   , np.float64 ), \
					   ('Min dt '   , np.float64 ), \
					   ('eta param' , np.float64 ), \
					   ('N snaps'   , np.int64   ), \
					   ('Max dE'    , np.float64 ), \
					   ('Use GPU'   , np.str_, 1 ), \
					   ('Use double', np.str_, 1 ), \
					   ('UNITS'     , unit_type  )] )
	
	model_params = np.dtype( [ \
					   ( 'Np'       , np.int32  ), \
					   ( 'Status'   , np.str_, 3), \
					   ( 'Hidden'   , np.str_, 3), \
					   ( 'Type'     , np.str_,32), \
					   ( 'Others'   , object    )] )
	
	model_type = np.dtype( [ \
					    ('Name'           , np.str_    ,     64),\
						('Description'    , np.str_    ,    512),\
						('Parameters'     , model_params       ),\
						('Phase coords'   , object             )])
	"""
		Name is the model name, as long as 63 characters.
		Description is a short description of what the model is. Useful!
		Parameters is a 32 element structure, dtype "model_params". 
		You can look for the fields in the structure doc.
		Phase coords is defined as a python object, but most of the
		time it will be a N_model x 7 matrix containing the phase
		coordinates of the particles within the model.
	"""
	
	def __init__(self):
		self.parameters = np.zeros( (1,), dtype=sim_type )
		self.models     = []

	def load_sim_params( filename, self ):
		
		table = np.zeros( (1,), dtype=sim_type )
		
		table = np.loadtxt( filename, dtype=sim_type )
		
		self.parameters = table

	def add_model( model, self ):
		
		self.models.append( model )
		
		if model['Parameters']['Status'] == 'on':
			
			if model['Parameters']['Type'] == 'massive':			
				self.parameters['N massive'] += model['Parameters']['Np'] 
	
			if model['Parameters']['Type'] == 'massless':
				self.parameters['N massless'] += model['Parameters']['Np'] 

		
		
		
		
		
